package com.stars.empoly.utils

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.layout.QMUIFrameLayout
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.popup.QMUIPopup
import com.qmuiteam.qmui.widget.popup.QMUIPopups
import com.stars.empoly.R
import com.stars.empoly.inte.ChoiceData

/**
 * 选择支付类型
 *Created by shihuiyun
 *on 2020/9/21
 */
object  PopuChosePayUtils {

    fun show(context: Context,money:String?, view: View, choiceData:ChoiceData){

        var mNormalPopup = QMUIPopups.fullScreenPopup(context)
        val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
        val frameLayout = QMUIFrameLayout(context)
        //自定义布局
        val layoutInflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var layout = layoutInflater.inflate(R.layout.popu_chose_pay, null)

        val ll:LinearLayout=layout.findViewById(R.id.ll)
        val imgClose:ImageView=layout.findViewById(R.id.img_close)
        val tvMoney:TextView=layout.findViewById(R.id.tv_money)
        val llWx:LinearLayout=layout.findViewById(R.id.ll_wx)
        val imgWx:ImageView=layout.findViewById(R.id.img_wx)
        val llZhi:LinearLayout=layout.findViewById(R.id.ll_zhi)
        val imgZhi:ImageView=layout.findViewById(R.id.img_zhi)
        tvMoney.text=money

        var type=""
        llWx.onClick {
            type="2"
            llWx.setBackgroundResource(R.drawable.bg_pay_on)
            llZhi.setBackgroundResource(R.drawable.bg_pay_off)
            imgWx.visibility=View.VISIBLE
            imgZhi.visibility=View.GONE

            if(null!=choiceData){
                choiceData.onRestuse(type)
                mNormalPopup.dismiss()
            }

        }
        llZhi.onClick {
            type="3"
            llWx.setBackgroundResource(R.drawable.bg_pay_off)
            llZhi.setBackgroundResource(R.drawable.bg_pay_on)
            imgWx.visibility=View.GONE
            imgZhi.visibility=View.VISIBLE
            if(null!=choiceData){
                choiceData.onRestuse(type)
                mNormalPopup.dismiss()
            }
        }



        imgClose.onClick {
            mNormalPopup.dismiss()
        }
        ll.onClick {

        }

        builder.release();

        val size = QMUIDisplayHelper.getScreenWidth(context)
        val height = QMUIDisplayHelper.getScreenHeight(context)


        val lp: FrameLayout.LayoutParams = FrameLayout.LayoutParams(size,
                height)
        frameLayout.addView(layout, lp)


        mNormalPopup.addView(frameLayout)
        mNormalPopup.onDismiss() {
        }

        mNormalPopup.dismissIfOutsideTouch(false)
        mNormalPopup.animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
        mNormalPopup.show(view)


    }




}
